using UnityEngine;

public class Fruit : MonoBehaviour
{
    public GameObject collectedEffect;
    public int score = 100;

    private SpriteRenderer _spriteRenderer;
    private CircleCollider2D _circleCollider2D;
    private Animator _animator;
    
    private static readonly int Type = Animator.StringToHash("type");

    // Start is called before the first frame update
    void Start()
    {
        _spriteRenderer = GetComponent<SpriteRenderer>();
        _circleCollider2D = GetComponent<CircleCollider2D>();
        _animator = GetComponent<Animator>();
        
        _animator.SetInteger(Type, Random.Range(0, 3));
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            _spriteRenderer.enabled = false;
            _circleCollider2D.enabled = false;
            
            collectedEffect.SetActive(true);

            GameController.instance.AddScore(score);

            Destroy(gameObject, 0.2f);
        }
    }
}
